<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/com.css" />
		<link rel="stylesheet" type="text/css" href="css/table.css" />
		<script src="lib/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/api.js" type="text/javascript" charset="utf-8"></script>
		<script src="lib/js.cookie.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>

		<fieldset id="">
			<legend>登录管理员</legend>

			<input type="text" value="4545">
			<input type="password" value="4545">
			<input type="button" value="登录">
		</fieldset>

		<script type="text/javascript">
			let ipts = document.querySelectorAll('input')
			ipts[2].onclick = function() {

				axios.post(regApi, {
					username: ipts[0].value,
					password: ipts[1].value
				}).then(res => {
					console.log(res)
				})

				axios.get(loginApi, {
					params: {
						username: ipts[0].value,
						password: ipts[1].value
					}
				}).then(res => {
					console.log(res)
					if (res.data.code == 1) {
						Cookies.set('id', res.data.data.id, {
							expires: 365
						})
						Cookies.set('username', res.data.data.username, {
							expires: 365
						})

						alert('登录成功')
						location.href = 'index.html'
					} else {
						alert(res.data.msg)
						alert("请先注册并申请管理")
					}
				})

			}
		</script>

	</body>
</html>
